<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateHufeiTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //商户mch
        Schema::create('mch', function (Blueprint $table){
            $table->increments('id');
            $table->string('mch_no',20);
            $table->string('name',40);
            $table->string('shortname',20);
            $table->string('goodsname',20);
            $table->string('legal_name',20);
            $table->integer('agent_id');
            $table->string('username',20);
            $table->string('password',40);
            $table->char('salt',6);
            $table->string('key',32);
            $table->string('contact',20);
            $table->string('mobile',20);
            $table->tinyInteger('status');
            $table->integer('type');
            $table->text('account_bank');
            $table->string('account_area',20);
            $table->string('account_user',20);
            $table->string('account_no',40);
            $table->string('url',100)->nullable();
            $table->string('token',40)->nullable();
            $table->dateTime('login_time')->nullable();
            $table->string('remark',200);
            $table->string('verify_remark',200)->nullable();
            $table->dateTime('addtime');
            $table->decimal('fee_rate',4,2);
            $table->integer('limit_pay');
        });
        
        //代理商agent
        Schema::create('agent', function (Blueprint $table){
            $table->increments('id');
            $table->string('agent_no',20);
            $table->string('name',20);
            $table->integer('seller_id');
            $table->tinyInteger('status');
            $table->string('username',20);
            $table->string('password',40);
            $table->char('salt',6); 
            $table->string('legal_name',20);
            $table->text('email');
            $table->string('contact',20);
            $table->string('mobile',20);
            $table->text('account_bank');
            $table->string('account_area',20);
            $table->string('account_user',20);
            $table->string('account_no',40);
            $table->decimal('finance_rate',4,2);
            $table->decimal('game_rate',4,2);
            $table->decimal('other_rate',4,2);
            $table->decimal('t0_rate',4,2);
            $table->decimal('d0_rate',4,2);
            $table->string('token',40)->nullable();
            $table->dateTime('login_time')->nullable();
        });
        
        //销售seller
        Schema::create('seller', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',20);
            $table->string('username',20);
            $table->string('password',40);
            $table->char('salt',6); 
            $table->string('token',40);
            $table->dateTime('login_time');
            $table->integer('status');
        });
        
        //通道tunnel
        Schema::create('tunnel', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',20);
            $table->string('function',20);
            $table->string('pc_function',20);
            $table->string('wx_function',20);
            $table->string('alipay_function',20);
        });
        
        //路由route
        Schema::create('route', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('mch_id');
            $table->integer('tunnel_id');
            $table->string('tunnel_no',40);
            $table->string('tunnel_key',40)->nullable();
            $table->tinyInteger('status');
            $table->tinyInteger('t0flag');
            $table->dateTime('addtime');
            $table->dateTime('verify_time')->nullable();
            $table->string('mch_name',20);
            $table->decimal('trade_rate',10,5);
            $table->decimal('draw_rate',10,5);
            $table->decimal('draw_base',4,2);
            $table->decimal('settle_base',4,2);
            $table->text('account_bank');
            $table->string('bank_code',20);
            $table->string('account_user',20);
            $table->string('account_no',40);
        });
        
        //交易订单order_detail
        Schema::create('order_detail', function (Blueprint $table) {
            $table->increments('id');
            $table->string('serialno',30);
            $table->decimal('money',14,2);
            $table->decimal('fee',14,2);
            $table->integer('mch_id');
            $table->decimal('agent_fee',14,2);
            $table->integer('agent_id');
            $table->integer('seller_id');
            $table->datetime('addtime');
            $table->datetime('backtime')->nullable();
            $table->tinyInteger('status');
            $table->integer('tunnel_id');
            $table->string('code',100)->nullable();
            $table->text('post_detail')->nullable();
            $table->text('return_detail')->nullable();
            $table->string('out_serialno',30)->nullable();
            $table->string('notify_url',30)->nullable();
            $table->integer('type')->nullable();
            $table->integer('method');
            $table->integer('notify_time')->nullable();
        });
        
        //管理员admin
        Schema::create('admin', function (Blueprint $table){
            $table->increments('id');
            $table->string('name',20);
            $table->string('username',20);
            $table->string('password',40);
            $table->char('salt',6); 
            $table->string('token',40)->nullable();
            $table->dateTime('login_time')->nullable();
        });
        
        //提现表mch_withdraw
        Schema::create('mch_withdraw', function (Blueprint $table){
            $table->increments('id');
            $table->integer('mch_id');
            $table->integer('tunnel_id');
            $table->string('tunnel_no',40);
            $table->dateTime('addtime');
            $table->dateTime('backtime')->nullable();
            $table->text('return_detail')->nullable();
            $table->tinyInteger('status');
            $table->integer('type');
            $table->text('post_detail');
            $table->string('serialno',40);
            $table->decimal('money',14,2)->nullable();
            $table->decimal('fee',14,2)->nullable();
        });
        
        //商户修改申请表 mch_modify
        Schema::create('mch_modify', function (Blueprint $table){
            $table->increments('id');
            $table->integer('mch_id');
            $table->integer('agent_id');
            $table->dateTime('addtime');
            $table->decimal('fee_rate',4,2);
            $table->integer('limit_pay');
            $table->decimal('draw_rate',10,5);
            $table->integer('status');
        });
        
        //测试表 test
        Schema::create('test', function (Blueprint $table){
            $table->increments('id');
            $table->text('content');
            $table->string('type',20);
            $table->dateTime('addtime');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('mch');
        Schema::drop('agent');
        Schema::drop('seller');
        Schema::drop('tunnel');
        Schema::drop('route');
        Schema::drop('order_detail');
        Schema::drop('admin');
        Schema::drop('mch_withdraw');
        Schema::drop('test');
    }
}
